
/**
 *  @file wave_audio.h
 *
 *  \brief Wave Audio Module API Header File
 *
 *  This Header File contains declaration of Wave Audio APIs, various Macros
 *  and Constant Definitions for use in interested applications.
 */

/*
 *  Copyright (C) 2013. Mindtree Ltd.
 *  All rights reserved.
 */

#ifndef _H_WAVE_AUDIO_
#define _H_WAVE_AUDIO_

/* ----------------------------------------- Header File Inclusion */
#include "BT_common.h"


/* ----------------------------------------- Tunable Constants */
/*
 *  Size of each Recording Block. Application provided callback will
 *  be called whenever this much size of raw audio is recorded.
 *
 *  Minimum Value: 256
 *  Maximum Value: anything
 */
#define WA_RECORD_BLOCK_SIZE                    4096 /* 4608 */


/*
 *  Number of Audio Recording Blocks to be configured. The Sound Driver
 *  works well when given a circular queue of Buffers onto which it
 *  copies the recorded data and let us know when finished recording each
 *  block. This constant defines the number of such blocks.
 *
 *  Minimum Value: 10
 *  Maximum Value: anything
 */
#define WA_RECORD_NUM_BLOCKS                    5 /* 20 */


/*
 *  Size of each Playing Block.
 *
 *  Minimum Value: 512
 *  Maximum Value: anything
 */
/* #define WA_PLAY_BLOCK_SIZE                      8192 */


/*
 *  Number of Audio Playing Blocks to be configured. The Sound Driver
 *  works well when given a circular queue of Buffers from which it
 *  copies the data to be played and let us know when finished playing
 *  each block. This constant defines the number of such blocks.
 *
 *  Minimum Value: 10
 *  Maximum Value: anything
 */
#define WA_PLAY_NUM_BLOCKS                      20


/* ----------------------------------------- Global Definitions */

/**
 *  @name Name
 *  Brief Description
 */

/*@{*/

/*@}*/


/* ----------------------------------------- Internal Macros */

/*@{*/
/** \if INTERNAL_MACROS */

#define WA_ERR                  fprintf
#define WA_PRINT_DEVICE         stderr

/** \endif */
/*@}*/


#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

/* ----------------------------------------- Structures/Data Types */

/**
 *  \typedef Wave Audio Recorder Callback
 *  \brief   Wave Audio Recorder Callback
 *
 *  Detailed Description.
 *
 *  \param [in] recorded_data
 *         Holds the recorded audio data
 *  \param [in] recorded_data_size
 *         Holds the size of recorded audio data
 *
 *  \return None
 *
 *  \sa
 */
typedef void (* WA_RECORD_CALLBACK)
             (
                 /* IN */ UCHAR *  recorded_data,
                 /* IN */ UINT16   recorded_data_size
             );

typedef void (* WA_PLAY_CALLBACK)
             (
                 /* IN */ UCHAR *  played_data,
                 /* IN */ UINT16   played_data_size
             );

/* ----------------------------------------- Macros */

/**
 *  @name Name
 *  Brief Description
 */

/*@{*/

/**
 *  Detailed Description
 *
 *  \param [in] param_1
 *         Param-1
 *
 *  \hideinitializer
 */

/*@}*/

/* ----------------------------------------- Internal Functions */

/*@{*/
/** \if INTERNAL_FUNCTIONS */

/** \endif */
/*@}*/


/* ----------------------------------------- API Declarations */

/**
 *  @name Wave Audio Recorder APIs
 */

/*@{*/

/**
 *  \brief To initialize Waveform Audio Input Device
 *
 *  \par Description:
 *  This function initializes the Waveform Audio Input Device for the
 *  rewuired parameters
 *
 *  \param [in] samples_per_sec
 *         The Sampling Frequency in Hz at which the recording needs to
 *  \param [in] bits_per_sample
 *         The number of bits per sample. Usually, 8 or 16.
 *  \param [in] number_of_channels
 *         The number of channels. Usually, 1 (Mono) or 2 (Stereo).
 *  \param [in] wa_record_size
 *         The size of one block of recorded data.
 *  \param [in] callback
 *         The application provided function to call when one block
 *         of data is recorded.
 *
 *  \return INT32
 *           0: Successful
 *          -1: Incorrect use, device already opened ?
 *          -2: Failed to open Waveform Audio Input Device
 *          -3: Failed to prepare Waveform Audio Headers
 *          -4: Failed to add Waveform Audio Headers
 *
 *  \sa
 *  MSDN: Waveform Audio Overview
 *  (MSDN Library > SDK Documentation > Multimedia Audio)
 */
INT32 wa_record_init
      (
          /* IN */  UINT16               samples_per_sec,
          /* IN */  UCHAR                bits_per_sample,
          /* IN */  UINT16               number_of_channels,
          /* IN */  UINT16               wa_record_size,
          /* IN */  WA_RECORD_CALLBACK   callback
      );


INT32 wa_record_start ( void );
INT32 wa_record_stop ( void );
INT32 wa_record_shutdown ( void );

/*@}*/


/**
 *  @name Wave Audio Recorder APIs
 */

/*@{*/

INT32 wa_play_init
      (
          /* IN */  UINT16               samples_per_sec,
          /* IN */  UCHAR                bits_per_sample,
          /* IN */  UINT16               number_of_channels,
          /* IN */  WA_PLAY_CALLBACK     callback,
          /* IN */  UINT32               no_of_playblocks
      );

INT32 wa_play_shutdown ( void );

INT32 wa_play_set_volume (UINT32 volume);

INT32 wa_play_write
      (
          /* IN */  UCHAR *  data,
          /* IN */  UINT16   datalen
      );

/*@}*/

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _H_WAVE_AUDIO_ */

